<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    /**
     * Front Controller
     */
    private static $front = null;

    /**
     * Application configuration	 
     */
    private static $configuration = null;

    /**
     * Registration of my name space
     */
    protected function initNamespace() {
        Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true)
                ->suppressNotFoundWarnings(false);
    }

    /**
     * Init application configuration
     */
    protected function initAppConfiguration() {
        self::$configuration = My_Global::getApplicationIni();
    }


    /**
     * Zend_Front_Controller created on each request
     */
    protected function initFrontController() {
        //Init frontController
        self::$front = Zend_Controller_Front::getInstance();
        switch (APP_ENV) {
            case 'production':
            case 'staging':
            case 'qc':
                self::$front->throwExceptions(false);
                break;
            default:
                self::$front->throwExceptions(true);
                break;
        }
    }

    protected function initSession() {
        Zend_Session::start();
    }

   
    public function run() {
        $this->initSession();
        //Init namspace
        $this->initNamespace();

        //Init Application Configuration
        $this->initAppConfiguration();

        //Init Front Controller
        $this->initFrontController();

        //Check default module
        if (null === self::$front->getControllerDirectory(self::$front->getDefaultModule())) {
            throw new Zend_Exception(
                    'No default controller directory registered with front controller'
            );
        }
      self::$front->registerPlugin(new My_Plugin_Env());
        //Dispatch controller
        self::$front->setParam('bootstrap', $this);
        self::$front->dispatch();
    }

}

